package itbour.onetouchshow.utils.crop.clippath;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Region;
import android.util.Log;

import itbour.onetouchshow.utils.crop.BaseLayerView;


/**
 * 采用Canvas.clipPath(..)方式实现的预览层
 */
public class ClipPathLayerView extends BaseLayerView {

    public ClipPathLayerView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {

        if (mShape == null) {
            Log.e("ClipPathLayerView", "Warning:Shape is null");
            if (mMask != null) {
                mMask.draw(this, canvas);
            }
            return;
        }
        if (!(mShape instanceof IClipPathShape)) {
            Log.e("ClipPathLayerView", "Shape must be subclass ofIClipPathShape ");
            return;
        }
        IClipPathShape shape = (IClipPathShape) mShape;
        Path path = shape.createShapePath(this);
        canvas.save();
        canvas.clipPath(path, Region.Op.DIFFERENCE);
        if (mMask != null) {
            mMask.draw(this, canvas);
        }
        canvas.restore();
        canvas.drawPath(path, shape.createShapePaint());

    }
}
